//
//  DPUtilities.h
//  UITestingKit
//
//  Created by Ofri Wolfus on 30/01/07.
//  Copyright 2007 Ofri Wolfus. All rights reserved.
//


#import <UITestingKit/DPObjCRuntime.h>


#define DPGetMethodName() [NSString stringWithFormat:@"%@[%@ %@]", \
	object_isInstance(self) ? @"-" : @"+", [self className], NSStringFromSelector(_cmd)]

@class NSAssertionHandler;

/* Asserts for Objective-C that accepts unlimited number of arguments */
#if !defined(NS_BLOCK_ASSERTIONS)

#if !defined(DPAssert)
/*
 * The usage of this macro is the same as with NSAssert, exept you don't need DPAssert1, DPAssert2, etc.
 * This macro accepts any number of arguments passed to the description.
 */
#define DPAssert(condition, desc...)\
do {\
	if (!(condition)) {\
		[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd\
															object:self\
															  file:[NSString stringWithUTF8String:__FILE__] \
														lineNumber:__LINE__\
													   description:desc];\
	}\
} while(0)
#endif

#if !defined(DPCAssert)
/*
 * The usage of this macro is the same as with NSAssert, exept you don't need DPAssert1, DPAssert2, etc.
 * This macro accepts any number of arguments passed to the description.
 */
#define DPCAssert(condition, desc...)\
do {\
	if (!(condition)) {\
		[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__]\
																file:[NSString stringWithUTF8String:__FILE__] \
														  lineNumber:__LINE__\
														 description:desc];\
	}\
} while(0)
#endif

#endif	// !defined(NS_BLOCK_ASSERTIONS)


/*!
 * @abstract Sets up an autorelease pool that's automatically released
 * and recreated at each entry of the current runloop.
 * @discussion The autorelease pool is added to the current runloop in
 * <code>runLoopMode</code>. If <code>runLoopMode</code> is <code>nil</code>,
 * the pool is added to the current mode.
 * Each call to this function creates and sets up a new autorelease pool.
 */
DP_EXTERN void DPSetUpAutoreleasePool(NSString *runLoopMode);

/*!
 * @abstract Finds and returns the PID of a running process with a given
 * bundle identifier.
 * @discussion If a matching process is not found, <code>NO</code> is returned
 * and <code>pid</code> is not modified.
 */
DP_EXTERN BOOL DPGetPIDOfProcess(NSString *bundleIdentifier, pid_t *pid);
